package ${cfg.controllerRootPackage};

<#if cfg.enhanceService ==true>
import ${cfg.modelPackage}.${entity}DTO;
<#else>
import ${package.Entity}.${entity};
</#if>
import ${cfg.apiInterfacePackage}.I${entity}ScRemote;
import com.mcst.easyfk.base.dto.returns.DataResponse;
import com.mcst.easyfk.base.dto.search.PageSearch;
import com.mcst.easyfk.base.dto.search.SearchConditionBuilder;
import com.mcst.easyfk.base.utils.common.DataResponseBuilder;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "${entity}相关接口")
@RestController
@RequestMapping("/api/${cfg.moduleName?uncap_first}/${entity?uncap_first}")
public class ${entity}Controller {
@Resource
private I${entity}ScRemote ${entity?uncap_first}ScRemote;

/**
* 根据Id值查询
*
* @param id
* @return
*/
@ApiOperation("根据Id值查询")
@GetMapping("/detail")
<#if cfg.enhanceService ==true>
public DataResponse detail(String id) {
<#else>
public DataResponse detail(Object id) {
</#if>
    return DataResponseBuilder.buildSuccessBody(this.${entity?uncap_first}ScRemote.detail(id));
}

/**
* 根据条件查询
*
* @param ${entity?uncap_first}
* @return
*/
@ApiOperation("根据条件查询")
@GetMapping("/queryOne")
<#if cfg.enhanceService ==true>
   public DataResponse queryOne(${entity}DTO ${entity?uncap_first}) {
<#else>
   public DataResponse queryOne(${entity} ${entity?uncap_first}) {
</#if>
        SearchConditionBuilder builder = new SearchConditionBuilder().buildExample(${entity?uncap_first});
        return DataResponseBuilder.buildSuccessBody(this.${entity?uncap_first}ScRemote
        .queryOne(builder.getCondition()));
}

/**
* 据条件查询数据
*
* @param ${entity?uncap_first} 条件
* @return 查询到的集合列表
*/
@ApiOperation("列表查询")
@GetMapping(value = "/queryList")
<#if cfg.enhanceService ==true>
public DataResponse queryList(${entity}DTO ${entity?uncap_first}) {
<#else>
public DataResponse queryList(${entity}DTO ${entity?uncap_first}) {
</#if>
  SearchConditionBuilder builder = new SearchConditionBuilder().buildExample(${entity?uncap_first});
  return DataResponseBuilder.buildSuccessBody(this.${entity?uncap_first}ScRemote
            .queryList(builder.getCondition()));
}

/**
* 分页查询
* @param pageSearch
* @param ${entity?uncap_first}
* @return
*/
@ApiOperation("分页查询")
@GetMapping(value = "/queryPage")
<#if cfg.enhanceService ==true>
public DataResponse queryPage(PageSearch pageSearch, ${entity}DTO ${entity?uncap_first}) {
<#else>
public DataResponse queryPage(PageSearch pageSearch, ${entity}DTO ${entity?uncap_first}) {
</#if>
  SearchConditionBuilder builder = new SearchConditionBuilder().buildExampleAndPage(pageSearch, ${entity?uncap_first});
  return DataResponseBuilder.buildBodyByPageResult(this.${entity?uncap_first}ScRemote
                .queryPage(builder.getCondition()));
}


/**
* 保存对象
*
* @param entity 实体对象
* @return
*/
@ApiOperation("添加数据")
@PostMapping(value = "/save")
<#if cfg.enhanceService ==true>
public DataResponse save(@Validated @RequestBody ${entity}DTO entity) {
<#else>
public DataResponse save(@Validated @RequestBody ${entity} entity) {
</#if>
  return DataResponseBuilder.buildBodyByBaseResult(this.${entity?uncap_first}ScRemote.save(entity));
}


/**
* 根据实体对象删除数据
*
* @param entity 实体对象
* @return BaseResult 里面的obj对象是影响行数
*/
@ApiOperation("根据实体对象删除数据")
@PostMapping(value = "/delete")
<#if cfg.enhanceService ==true>
public DataResponse delete(@Validated @RequestBody ${entity}DTO entity) {
<#else>
public DataResponse delete(@Validated @RequestBody ${entity} entity) {
</#if>
return DataResponseBuilder.buildBodyByBaseResult(this.${entity?uncap_first}ScRemote.delete(entity));
}


/**
* 修改部分数据，如果实体对象的某个属性为null则不更新
*
* @param entity
* @return
*/
@ApiOperation("修改数据")
@PostMapping(value = "/update")
<#if cfg.enhanceService ==true>
public DataResponse update(@Validated @RequestBody ${entity}DTO entity) {
<#else>
public DataResponse update(@Validated @RequestBody ${entity} entity) {
</#if>
  return DataResponseBuilder.buildBodyByBaseResult(this.${entity?uncap_first}ScRemote.update(entity));
}
}